<template>
  <el-dialog title="提示" :visible.sync="$store.state.dia.export.show" width="30%" class="export-box">

    <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
    <div style="margin: 15px 0;"></div>
    <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
      <el-checkbox v-for="city in cities" :label="city" :title="city" :key="city">{{city}}</el-checkbox>
    </el-checkbox-group>

    <span slot="footer" class="dialog-footer">
      <el-button @click="$store.state.dia.export.show = false">取 消</el-button>
      <el-button type="primary" @click="sure">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  components: {},
  name: "",
  data() {
    return {
      checkAll: true,
      checkedCities: ["上海", "北京"],
      cities:["上海", "北京"],
      isIndeterminate: false
    };
  },
  methods: {
    sure() {
      if(this.$store.state.dia.export.OK!=null){
        this.$store.state.dia.export.info.forEach(ele => {
          if(this.checkedCities.includes(ele[1])){
            this.$store.state.dia.export.params.push(ele)
          }
        });
        this.$store.state.dia.export.OK()
        this.$store.state.dia.export.show = false;
        return
      }
      var params=this.$store.state.dia.export.search
      params.exportWhere=[]
      this.$store.state.dia.export.info.forEach(ele => {
        if(this.checkedCities.includes(ele[1])){
          params.exportWhere.push(ele)
        }
      });

      // console.log(params)
      // return

      this.apiPost("studentinfo/export",params).then(res=>{
          _g.toastMsg(res.error?"error":"success",res.msg)
          if(!res.error)location.href=res.data
        })
      this.$store.state.dia.export.show = false;
    },
    handleCheckAllChange(val) {
      this.$set(this,'checkedCities',this.checkAll ? this.cities : [])
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.cities.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.cities.length;
    }
  },
  created() {
    this.cities=this.$store.state.dia.export.info.map(val=>val[1])
    this.checkedCities=this.$store.state.dia.export.info.map(val=>val[1])
  }
};
</script>
<style scoped>
.tmpl {
}
</style>